import os
from urllib import parse
from xml import etree
import zipfile
import requests
import numpy as np
from astropy import units as u
from astropy import table
from astropy import wcs
from astropy.coordinates import Distance
from astropy.io import fits
import glue_jupyter as gj
from glue import core as gcore
We start by downloading the Gaia DR2 dataset for the 3 degree area around the Pleiades using astroquery
from astroquery import gaia
The below will either download the dataset and save it locally, or it will load the saved copy if you've already downloaded.
tab = gaia.Gaia.query_object_async('Messier 45', 90*u.arcmin)
tab = table.QTable(tab)
Now lets select a sub-set of interesting columns, and sub-sample on the part of the dataset that has a valid distance and is within a reasonable range that could be anywhere near us.
subtab = tab['designation', 'ra', 'dec', 'parallax', 'parallax_error', 'pmra', 'pmra_error', 'pmdec', 'pmdec_error',
'phot_g_mean_mag' ,'bp_rp']
subtab['distance'] = u.Quantity(subtab['parallax']).to(u.pc, u.parallax())
subtab['distance_error'] = u.Quantity(subtab['parallax_error']).to(u.pc, u.parallax())
subtab = subtab[np.isfinite(subtab['distance'])&(u.Quantity(subtab['distance'])<300*u.pc)&(subtab['distance']>0)]
len(subtab)
Now we set up a data object for Glupyter, and create a Glupyter app for further examination.
gaia_data = gcore.Data('Gaia_Pleiades', **subtab)
app = gj.jglue(gaia_data)
scats = []
view3d = app.scatter3d(x='ra', y='dec', z='distance')
scats.append(app.scatter2d(x='distance', y='phot_g_mean_mag'))
scats.append(app.scatter2d(x='bp_rp', y='phot_g_mean_mag'))
state = scats[-1].state
state.y_max, state.y_min = state.y_min, state.y_max
scats.append(app.scatter2d(x='pmra', y='pmdec'))
scats[-1].scale_x.min = -100
scats[-1].scale_x.max = 100
scats[-1].scale_y.min = -100
scats[-1].scale_y.max = 100
scats.append(app.scatter2d(x='pmra', y='pmra_error'))
scats[-1].state.x_min, scats[-1].state.x_max = -50, 50
scats.append(app.scatter2d(x='pmdec', y='pmdec_error'))
scats[-1].state.x_min, scats[-1].state.x_max = -100, 50
Now go ahead a select a subset using all the plots above...
if len(gaia_data.subsets) == 0:
print("You didn't select anything before running this cell, "
"so I'll select the brightest stars for you!")
app.subset('Bright stars', gaia_data.id['phot_g_mean_mag'] < 8)
seltab = subtab[gaia_data.subsets[0].to_mask()]
And compute the distance to the Pleiades!
np.mean(seltab['distance'])
Or some percentiles
np.percentile(seltab['distance'], [10, 32, 50, 68, 90])
And while we're at it - lets see what the mean proper motion is:
np.mean(seltab['pmra']), np.mean(seltab['pmdec'])
np.mean(np.hypot(seltab['pmra']*np.cos(seltab['dec']), seltab['pmdec']))
Now we look at an HST image of a small part of the Pleiades, and try overplotting some of the Gaia stars
from astroquery.mast import Observations
mast_qry = Observations.query_criteria(target_name='PLEIADESFIELD1B', obs_collection='hst')
mast_qry
Now lets download just the final drizzled image for the observation with the bluer filter (highest resolution): F475W
result = Observations.download_products(mast_qry['obsid'][mast_qry['filters']=='F475W'], productSubGroupDescription='DRZ')
result['Local Path']
assert len(result) == 1
f475w_image = fits.open(result['Local Path'][0])
Now we add the image data to glue and display it:
sciim = app.add_data(f475w=f475w_image)[0]
imview = app.imshow(data=sciim)
Now we glue together the image and the Gaia data. (Note that it might take some time for the view to catch up after you make the link.)
app.add_link(gaia_data, 'ra', sciim, 'Right Ascension')
app.add_link(gaia_data,'dec', sciim, 'Declination')
imview.add_data(gaia_data)
Markers should appear in the image viewer. You may need to fiddle with the color a bit to see the markers. Since you've already made your subset selection: are any of the Pleiades members in the HST field?
You'll probably see them: they are there, but clearly offset from where the HST image has them! This might at first appear to be a bug, but it's not. Why might this be?